package org.jeecg.modules.business.system.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.modules.business.system.entity.WmsSystemConfig;
import org.jeecg.modules.business.system.mapper.WmsSystemConfigMapper;
import org.jeecg.modules.business.system.service.IWmsSystemConfigService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Description: 系统配置项
 * @Author: jeecg-boot
 * @Date:   2023-07-27
 * @Version: V1.0
 */
@Service
public class WmsSystemConfigServiceImpl extends ServiceImpl<WmsSystemConfigMapper, WmsSystemConfig> implements IWmsSystemConfigService {


    /**
     * 更新初始化数据
     * 
     * @author DongPeng
     * @date 2023/8/11 14:21
     * @param wmsSystemConfig 参数
     * @return
     */
    @Override
    public void updateEndDate(WmsSystemConfig wmsSystemConfig) {
        if (ObjectUtil.isNotEmpty(wmsSystemConfig) && ObjectUtil.isNotEmpty(wmsSystemConfig.getInitEndDate())) {
            Date startDate = wmsSystemConfig.getInitStartDate();
            Date endDate = wmsSystemConfig.getInitEndDate();
            if (endDate.before(startDate)) {
                throw new JeecgBootException("结束日期不可早于开始日期！");
            }
        }
        this.updateById(wmsSystemConfig);
    }

    /**
     * 操作状态判断
     *
     * @author DongPeng
     * @date 2023/8/14 13:17
     * @param
     * @return String
     */
    @Override
    public String execJudge() {
        List<WmsSystemConfig> list = this.list();
        if (ObjectUtil.isNotEmpty(list)) {
            WmsSystemConfig wmsSystemConfig = list.get(0);
            if (ObjectUtil.isEmpty(wmsSystemConfig.getInitStartDate())) {
                throw new JeecgBootException("未进行启用初始化日期！");
            }else if (StrUtil.isNotEmpty(wmsSystemConfig.getIsFinished()) && "1".equals(wmsSystemConfig.getIsFinished())) {
                throw new JeecgBootException("初始化完成后不可操作！");
            }
            return "success";
        }else {
            throw new JeecgBootException("未进行启用初始化日期！");
        }
    }
}